package com.lxyk.service.student.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lxyk.dao.student.TransferDao;
import com.lxyk.dao.user.ClassesDao;
import com.lxyk.domain.Classes;
import com.lxyk.domain.StudentVO;
import com.lxyk.domain.StudentVO2;
import com.lxyk.service.student.TransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class TransferServiceImpl implements TransferService {

    @Autowired
    private ClassesDao classesDao;

    @Autowired
    private TransferDao transferDao;

    @Override
    public void transferHandler(StudentVO vo) {
        //根据班级id查询班级信息
        //当前班级
        Classes currentClass = classesDao.findById(vo.getCid());
        //转出班级
        Classes outClass = classesDao.findById(vo.getOid());
        String record = vo.getRecord();
        if (record == null || record.equals("")) {
            record = (currentClass.getClassName() + "-" + outClass.getClassName());
        } else {
            record += "-" + outClass.getClassName();
        }

        vo.setRecord(record);

        transferDao.transferHandler(vo);
    }

    @Override
    public PageInfo<StudentVO> transferByCid(Integer cid, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<StudentVO> list = transferDao.transferByCid(cid);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<StudentVO> findTransferByCondition(StudentVO vo, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<StudentVO> list = transferDao.findTransferByCondition(vo);
        return new PageInfo<>(list);
    }

    @Override
    public Integer findCountByCid(Integer cid) {
        return transferDao.findCountByCid(cid);
    }
}
